package com.ceba.test.modules.invalid.logicService;


import com.ceba.cebautils.DateUtil;
import com.ceba.forveri.bean.SigntureVeriResult;
import com.ceba.test.modules.filemanage.entity.GFile;
import com.ceba.test.modules.filemanage.service.GFileService;
import com.ceba.test.modules.invalid.entity.ReportInvalid;
import com.ceba.test.modules.invalid.service.ReportInvalidService;

public class InvalidLogicService {
	
	private ReportInvalidService reportInvalidService;
	private GFileService gFileService ;
	
	
	public GFileService getgFileService() {
		return gFileService;
	}


	public void setgFileService(GFileService gFileService) {
		this.gFileService = gFileService;
	}


	/**
	 * 添加一条记录
	 * @return
	 */
	public Boolean add(ReportInvalid rpi) throws Exception{
		return reportInvalidService.add(rpi);
	}
	
	
	/**
	 * 创建对象
	 * @param gFile
	 * @param uploadIp
	 * @param reason
	 * @param ri
	 * @return
	 */
	public boolean createInvalidReport(String id,GFile gFile, String uploadIp,
			String reason, ReportInvalid ri,String createUserName) throws Exception{
		  boolean suc =gFileService.addFile(gFile);
			ri.setId(id);
			ri.setUploadUserIp(uploadIp);
			ri.setReason(reason);
			ri.setFileName(gFile.getFileName());
			ri.setInvalidFileId(gFile.getId());
			
			//默认待审核
			ri.setStatus("2");
			ri.setCreatTime(DateUtil.getNowTime(null));
			if(suc){
				return add(ri);
			}
			return false;
	}
	
	
	
	public ReportInvalid packReportInValidFromSig(ReportInvalid reportInvalid, SigntureVeriResult svr){
		return reportInvalidService.packReportInValidFromSig(reportInvalid, svr);
	 }
	
	
	/*
	 * 更新作废文档信息
	 */
	public boolean updateReportInValid(ReportInvalid reportInvalid, SigntureVeriResult svr) throws Exception{
		return reportInvalidService.updateReportInValid(reportInvalid, svr);
	}
	
	/*
	 * 更新作废文档附件
	 * annix == 1 附件1
	 * annix == 2 附件2
	 */
	public boolean updateReportInValidByAnnix(GFile gFile, String reportId, int annix) throws Exception{
		  boolean suc =gFileService.addFile(gFile);
		  return  reportInvalidService.updateReportInValidByAnnix(gFile, reportId, annix,suc);
	}
	
	/**
	 * 通过id查找
	 * @param reportId
	 */
	public ReportInvalid getInvalidReportByReportId(String reportId) {
		return reportInvalidService.getInvalidReportByReportId(reportId);
	}
	
	
	/*
	 * 删除
	 */
	public boolean deleteReportByReportId(String reportId) {
		return reportInvalidService.deleteReportByReportId(reportId);
	}
	
	/**
	 * 更新某个属性的值
	 * @param id
	 * @param filed
	 * @param value
	 * @return
	 */
	public Boolean updateFiledValue(String id,String filed,String value) throws Exception{
		return reportInvalidService.updateFiledValue(id, filed, value);
	}
	
	/*
	 * 判断主键是否存在
	 */
	public boolean checkReportInvalidIdExsit(String id){
		return reportInvalidService.checkReportInvalidIdExsit(id);
	}
	
	/**
	 * 根据reportId查找审核报告
	 * @param reportId
	 * @return
	 */
	public boolean checkHasReportInvalid(String reportId) {
		return reportInvalidService.checkHasReportInvalid(reportId);
	}
	
	
	
	public ReportInvalidService getReportInvalidService() {
		return reportInvalidService;
	}

	public void setReportInvalidService(ReportInvalidService reportInvalidService) {
		this.reportInvalidService = reportInvalidService;
	}
	

}
